<template>
  <div class="goods-hot">
    <!-- 根据热榜类型 动态生成标题 -->
    <h3>{{title[types]}}</h3>
    <!-- 商品区块 -->
    <RouterLink to="/" class="goods-item" :key="item.id" v-for="item in good">
      <img :src="item.picture" alt="" />
      <p class="name ellipsis">{{item.name}}</p>
      <p class="desc ellipsis">{{item.desc}}</p>
      <p class="price">&yen;{{item.price}}</p>
    </RouterLink>
  </div>
</template>
<script>
import { ref } from 'vue'
import { findHotGoods } from '@/api/good'
import { useRoute } from 'vue-router'
export default {
  props: {
    // 商品热榜类型
    types: {
      type: Number,
      default: 1
    }
  },
  name: 'GoodsHot',
  setup (props) {
    const good = ref([])
    const route = useRoute()

    async function getGood () {
      // 传入id和热榜类型
      const res = await findHotGoods({ id: route.params.id, type: props.types })
      good.value = res.result
    }
    getGood()

    // 标题
    const title = {
      1: '24小时热销榜', 2: '周热销榜', 3: '总热销榜'
    }

    return { good, title }
  }
}
</script>
<style scoped lang="less">
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
  .goods-item {
    display: block;
    padding: 20px 30px;
    text-align: center;
    background: #fff;
    img {
      width: 160px;
      height: 160px;
    }
    p {
      padding-top: 10px;
    }
    .name {
      font-size: 16px;
    }
    .desc {
      color: #999;
      height: 29px;
    }
    .price {
      color: @priceColor;
      font-size: 20px;
    }
  }
}
</style>
